﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Webkit;
using LinkNote.Core;
using net.sgoliver;
using Android.Util;

namespace LinkNote
{
    [Activity(Label = "查看笔记")]
    public class NoteViewFullScreenActivity : Activity
    {
        private NoteViewActivity noteview;

        protected override void  OnCreate(Bundle bundle)
        {
            if (MainActivity.loginUser == null)
            {
                this.Finish();
                StartActivity(typeof(LoginActivity));
                return;
            } 
            base.OnCreate(bundle);
            this.RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.noteviewfullscreen);
            WebQuery.Init(this);

            noteview = this.FindViewById<NoteViewActivity>(Resource.Id.editor);
            ImageButton btnClose = this.FindViewById<ImageButton>(Resource.Id.btnClose);
            btnClose.Visibility = ViewStates.Visible;
            btnClose.Click += delegate
            {
                WebQuery.Init(MainActivity.Instance);
                this.Finish();
            };

            int fileid = this.Intent.GetIntExtra("fileid", 0);
            ShowNoteView(fileid);
        }

        public void ShowNoteView(int id)
        {
            LinkNoteFile file = DBHelper.sqlitedb.Find<LinkNoteFile>(id);
            if(file != null)
                noteview.SelectedNote = file;
        }

        public override void OnCreateContextMenu(IContextMenu menu, View v, IContextMenuContextMenuInfo info)
        {
            noteview.OnCreateContextMenu(menu, v, info);
            base.OnCreateContextMenu(menu, v, info);
        }

        public override bool OnContextItemSelected(IMenuItem item)
        {
            noteview.OnContextItemSelected(item);
            return base.OnOptionsItemSelected(item);
        }

        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            noteview.OnActivityResult(requestCode, resultCode, data);
        }

        protected override void OnPause()
        {
            base.OnPause();
            noteview.OnActivityPause();
        }
    }
}